
package projForWen;

import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;

/**
 *
 * @author Bacteria
 * Created on 2013-2-1, 11:39:03
 */
public class ListView extends JLabel implements  ListCellRenderer{
    private static final Color HIGHLIGHT_COLOR = new Color(0, 0, 128);
    
    public ListView(){
        setOpaque(true);
        setIconTextGap(5);
    }
    @Override
    public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
        if(value instanceof ListIcon){
            ListIcon item = (ListIcon)value;
            this.setIcon(item.getIcon());
            this.setText(item.getText());
            if (isSelected) {
                  setBackground(HIGHLIGHT_COLOR);
                  setForeground(Color.white);
            } else {
                  setBackground(Color.white);
                  setForeground(Color.black);
            }
            return this;
        }
        return null;
    }
}
